package ink.lovejinhu.leetcode;

public class Solution_0977 {
    /**
     * @param nums
     * @return
     */
    public int[] sortedSquares(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        for (; left <= right; ) {
            if (Math.abs(nums[left]) > Math.abs(nums[right])) {  //左指针比右指针的绝对值大
                swap(nums, left, right);
                right--;
            } else {
                left++;

            }

        }
        for (int i = 0; i < nums.length - 1; i++) {
            nums[i] = nums[i] * nums[i];
        }
        return nums;
    }

    public void swap(int nums[], int left, int right) {
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }

}
